<template>
	<view class="detail-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="答复详情"></uni-navbar></view>

		<view class="detail-info" v-if="replyInfo.id">
			<view class="info-title">
				<view class="title-top">{{ title }}</view>
			</view>
		</view>

		<view class="form-box form-box-show">
			<u-form>
				<u-form-item class="form-item" label="发文字号">{{ replyInfo.wordSize }}</u-form-item>
				<u-form-item class="form-item" label="签发人">{{ replyInfo.issueUser }}</u-form-item>
				<u-form-item class="form-item" label="答复类型">{{ replyInfo.replyTypeName }}</u-form-item>
				<u-form-item class="form-item" label="答复内容" label-position="top">
					<view class="input-text">{{ $htmlRegx(replyInfo.replyContent) }}</view>
				</u-form-item>
			</u-form>
		</view>

		<view class="file-list" v-if="fileList.length > 0">
			<view class="file-item" v-for="(item, index) in fileList" :key="index" @click="$showLine(item)">
				<view class="file-type"><image :src="imgpath(item.path)" mode="widthFix"></image></view>
				<view class="file-name clamp">
					{{ item.name }}
					<text class="file-time">{{ item.createTime }}</text>
				</view>
				<view class="right-type">预览</view>
			</view>
		</view>

		<view class="uploader-add" @click="onTts">
			<image v-if="!play" src="/static/img/icon_76.png" mode="widthFix"></image>
			<image src="/static/img/icon_77.gif" v-else mode="widthFix"></image>
		</view>

		<view class="form-box form-box-show">
			<u-form ref="uForm">
				<u-form-item class="form-item" label="联系人">{{ replyInfo.linker }}</u-form-item>
				<u-form-item class="form-item" label="联系电话">{{ replyInfo.linkerTel }}</u-form-item>
			</u-form>
		</view>
	</view>
</template>

<script>
import uniParse from '@/components/uni-parse/parse.vue';
import { mapState } from 'vuex';
export default {
	components: {
		uniParse
	},
	data() {
		return {
			typeList: {},
			typeMap: {
				1: '建议办理'
			},
			fileList: [],
			deptId: '',
			motionId: '',
			title: '',
			replyInfo: {},
			motionInfo: {
				title: ''
			},
			play: false
		};
	},
	onLoad(option) {
		this.loadLogin();
		this.motionId = option.motionId;
		this.deptId = option.deptId;
		this.title = decodeURI(option.title);
		this.loadData();
	},
	onHide() {
		this.$ttsOff();
	},
	onUnload() {
		this.$ttsOff();
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;
			} else {
				this.$logout();
			}
		},
		loadData() {
			let data = {
				motionId: this.motionId,
				deptId: this.deptId
			};
			this.$request('/motion/handler/reply/query', data).then((res) => {
				if (!res.data) {
					return false;
				}
				this.replyInfo = res.data.motionHandlerReply;
				this.fileList = res.data.fileList;
			});
		},
		imgpath(path) {
			let typeA = path.split('.');
			let type = (typeA[typeA.length - 1] || 'png').toLowerCase();
			return `/static/img/icon_${type}.png`;
		},
		onTts() {
			let text = `对${this.motionInfo.title}的答复`;
			text += ',' + this.replyInfo.replyTypeName;
			text += ',' + this.$htmlRegx(this.replyInfo.replyContent);
			this.$tts(text, this, 500);
		}
	}
};
</script>

<style lang="scss">
.detail-view {
	background-color: #fff;
}

.form-box {
	border-top: 10rpx solid $u-border-color;

	.form-item {
		@include mp-flex;
	}

	.input-text {
		width: 100%;
		text-align: left;
	}
}

.fiexd-btm {
	position: static;
	border-top: 10rpx solid $u-border-color;
	padding: 30rpx;
}
</style>
